package severlet;

import bean.Student;
import dao.AdminDao;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.ArrayList;

@WebServlet(name = "AdminSearchServlet", value = "/AdminSearchServlet")
public class AdminSearchServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");

        //获取前端
        String studentid = request.getParameter("studentid");
        String studentname = request.getParameter("studentname");
        String major = request.getParameter("major");
        String department = request.getParameter("department");
        String classes = request.getParameter("classes");
        String dormitoryid = request.getParameter("dormitoryid");
        String phoneid = request.getParameter("phoneid");

//        封装对象
        Student student=new Student();
        student.setStudentid(studentid);
        student.setStudentname(studentname);
        student.setMajor(major);
        student.setDepartment(department);
        student.setClasses(classes);
        student.setDormitoryid(dormitoryid);
        student.setPhoneid(phoneid);

        //传递到数据库进行模糊查询
        AdminDao adminDao=new AdminDao();
        ArrayList<Student> studentInfoByCondition = adminDao.getStudentInfoByCondition(student);
        //保存session
        request.getSession().setAttribute("studentInfo",studentInfoByCondition);

        request.getRequestDispatcher("admin_information.jsp").forward(request,response);
    }
}
